package thread;

public class SyncDemo {
    private static boolean success1 = false;
    private static boolean success2 = false;

    public static void main(String[] args) {
        Bank bank = new Bank();
        Thread t1 = new Thread(){
            public void run(){
                success1 = bank.getMoney(20000);
            }
        };
        Thread t2 = new Thread(){
            public void run(){
                success2 = bank.getMoney(20000);
            }
        };
        t1.start();
        t2.start();
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        if(success1&&success2){
            System.out.println("全部取款成功,出现并发安全!");
        }else{
            System.out.println("一人取款成功");
        }
    }
}
